## Winters 2010 WP

library(foreign)
library(Amelia)

## Load original dataset
w2010COM <- read.dta("W2010 WP Rep Data.dta")
head(w2010COM)
dim(w2010COM)
summary(w2010COM)

## Drop ID vars
w2010COM$lender <- w2010COM$NAMES_STD <- w2010COM$recipient <-w2010COM$MARKER <- w2010COM$countryname <- w2010COM$coding <- NULL

## Drop vars with no variation
w2010COM$gercol <- w2010COM$itcol <- NULL

## Drop calculated parameters
which( colnames(w2010COM)=="_mergeDPI" )

w2010COM <- w2010COM[-c(138)]

## How many variables? 144: reduction necessary
dim(w2010COM)

## Which variables are in analysis and have missing data?
sum(is.na(w2010COM $gmavg))/nrow(w2010COM)*100
sum(is.na(w2010COM $loggdppc1))/nrow(w2010COM)*100
sum(is.na(w2010COM $loginvest))/nrow(w2010COM)*100
sum(is.na(w2010COM $logdebtgni))/nrow(w2010COM)*100
sum(is.na(w2010COM $imf))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $logpop1))/nrow(w2010COM)*100
sum(is.na(w2010COM $loglandarea))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $trend))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $trend2))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $africa))/nrow(w2010COM)*100
sum(is.na(w2010COM $eastasia))/nrow(w2010COM)*100
sum(is.na(w2010COM $latinam))/nrow(w2010COM)*100
sum(is.na(w2010COM $mena))/nrow(w2010COM)*100
sum(is.na(w2010COM $southasia))/nrow(w2010COM)*100
sum(is.na(w2010COM $country))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $year))/nrow(w2010COM)*100 ## None
sum(is.na(w2010COM $pct_prog4))/nrow(w2010COM)*100 ##
sum(is.na(w2010COM $pct_natl5))/nrow(w2010COM)*100 ##

analysis <- as.data.frame(cbind(w2010COM$gmavg, w2010COM$loggdppc1, w2010COM$loginvest, w2010COM$logdebtgni, w2010COM$logpop1, w2010COM$africa, w2010COM$eastasia, w2010COM$latinam,w2010COM$mena, w2010COM$southasia, w2010COM$pct_prog4, w2010COM$pct_natl5))

missing <-as.data.frame(cbind(as.integer(complete.cases(w2010COM$gmavg)), as.integer(complete.cases(w2010COM$loggdppc1)), as.integer(complete.cases(w2010COM$loginvest)), as.integer(complete.cases(w2010COM$logdebtgni)), as.integer(complete.cases(w2010COM$logpop1)), as.integer(complete.cases(w2010COM$africa)), as.integer(complete.cases(w2010COM$eastasia)), as.integer(complete.cases(w2010COM$latinam)), as.integer(complete.cases(w2010COM$mena)), as.integer(complete.cases(w2010COM$southasia)), as.integer(complete.cases(w2010COM$pct_prog4)), as.integer(complete.cases(w2010COM$pct_natl5))))

dim(analysis)
dim(missing)
apply(missing, 2, sd)

## Remove analysis variables
## w2010COM$gmavg <- w2010COM$loggdppc1 <-w2010COM$loginvest <-w2010COM$logdebtgni <-w2010COM$logpop1 <-w2010COM$africa <-w2010COM$eastasia <-w2010COM$latinam <-w2010COM$mena <-w2010COM$southasia <- NULL
## head(w2010COM)
## var(w2010COM)

## Check correlations and missing values
round(cor(w2010COM$eurasia, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$eurasia, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$eurasia))/nrow(w2010COM)*100
## N
w2010COM$eurasia <- NULL

round(cor(w2010COM$ida_amt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$ida_amt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$ida_amt))/nrow(w2010COM)*100
## N
w2010COM$ida_amt <- NULL

round(cor(w2010COM$progamt1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$progamt1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$progamt1))/nrow(w2010COM)*100
## N
w2010COM$progamt1 <- NULL

round(cor(w2010COM$progamt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$progamt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$progamt2))/nrow(w2010COM)*100
## N
w2010COM$progamt2 <- NULL

round(cor(w2010COM$progamt3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$progamt3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$progamt3))/nrow(w2010COM)*100
## N
w2010COM$progamt3 <- NULL

round(cor(w2010COM$progamt4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$progamt4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$progamt4))/nrow(w2010COM)*100
## N
w2010COM$progamt4 <- NULL

round(cor(w2010COM$natlamt1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt1))/nrow(w2010COM)*100
## N
w2010COM$natlamt1 <- NULL

round(cor(w2010COM$natlamt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt2))/nrow(w2010COM)*100
## N
w2010COM$natlamt2 <- NULL

round(cor(w2010COM$natlamt3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt3))/nrow(w2010COM)*100
## N
w2010COM$natlamt3 <- NULL

round(cor(w2010COM$natlamt4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt4))/nrow(w2010COM)*100
## N
w2010COM$natlamt4 <- NULL

round(cor(w2010COM$natlamt5, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt5, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt5))/nrow(w2010COM)*100
## N
w2010COM$natlamt5 <- NULL

round(cor(w2010COM$natlamt6, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$natlamt6, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$natlamt6))/nrow(w2010COM)*100
## N
w2010COM$natlamt6 <- NULL

round(cor(w2010COM$commit_amt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt))/nrow(w2010COM)*100
## N
w2010COM$commit_amt <- NULL

round(cor(w2010COM$commit_amt1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt1))/nrow(w2010COM)*100
## N
w2010COM$commit_amt1 <- NULL

round(cor(w2010COM$commit_amt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt2))/nrow(w2010COM)*100
## N
w2010COM$commit_amt2 <- NULL

round(cor(w2010COM$commit_amt3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt3))/nrow(w2010COM)*100
## N
w2010COM$commit_amt3 <- NULL

round(cor(w2010COM$commit_amt4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt4))/nrow(w2010COM)*100
## N
w2010COM$commit_amt4 <- NULL

round(cor(w2010COM$commit_amt5, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt5, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt5))/nrow(w2010COM)*100
## N
w2010COM$commit_amt5 <- NULL

round(cor(w2010COM$commit_amt6, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$commit_amt6, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$commit_amt6))/nrow(w2010COM)*100
## N
w2010COM$commit_amt6 <- NULL

round(cor(w2010COM$numloan, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$numloan, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$numloan))/nrow(w2010COM)*100
## N
w2010COM$numloan <- NULL

round(cor(w2010COM$pctprog1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctprog1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctprog1))/nrow(w2010COM)*100
## N
w2010COM$pctprog1 <- NULL

round(cor(w2010COM$pctprog2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctprog2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctprog2))/nrow(w2010COM)*100
## N
w2010COM$pctprog2 <- NULL

round(cor(w2010COM$pctprog3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctprog3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctprog3))/nrow(w2010COM)*100
## N
w2010COM$pctprog3 <- NULL

round(cor(w2010COM$pctprog4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctprog4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctprog4))/nrow(w2010COM)*100
## N
w2010COM$pctprog4 <- NULL

round(cor(w2010COM$pctnatl1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl1))/nrow(w2010COM)*100
## N
w2010COM$pctnatl1 <- NULL

round(cor(w2010COM$pctnatl2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl2))/nrow(w2010COM)*100
## N
w2010COM$pctnatl2 <- NULL

round(cor(w2010COM$pctnatl3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl3))/nrow(w2010COM)*100
## N
w2010COM$pctnatl3 <- NULL

round(cor(w2010COM$pctnatl4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl4))/nrow(w2010COM)*100
## N
w2010COM$pctnatl4 <- NULL

round(cor(w2010COM$pctnatl5, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl5, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl5))/nrow(w2010COM)*100
## N
w2010COM$pctnatl5 <- NULL

round(cor(w2010COM$pctnatl6, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctnatl6, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctnatl6))/nrow(w2010COM)*100
## N
w2010COM$pctnatl6 <- NULL

round(cor(w2010COM$pctida, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctida, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctida))/nrow(w2010COM)*100
## N
w2010COM$pctida <- NULL

round(cor(w2010COM$pctibrd, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctibrd, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctibrd))/nrow(w2010COM)*100
## N
w2010COM$pctibrd <- NULL

round(cor(w2010COM$pctmix, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pctmix, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pctmix))/nrow(w2010COM)*100
## N
w2010COM$pctmix <- NULL

round(cor(w2010COM$bankpct, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$bankpct, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$bankpct))/nrow(w2010COM)*100
## N
w2010COM$bankpct <- NULL

round(cor(w2010COM$pct_prog1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_prog1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_prog1))/nrow(w2010COM)*100
## N
w2010COM$pct_prog1 <- NULL

round(cor(w2010COM$pct_prog2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_prog2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_prog2))/nrow(w2010COM)*100
## N
w2010COM$pct_prog2 <- NULL

round(cor(w2010COM$pct_natl1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_natl1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_natl1))/nrow(w2010COM)*100
## N
w2010COM$pct_natl1 <- NULL

round(cor(w2010COM$pct_prog3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_prog3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_prog3))/nrow(w2010COM)*100
## N
w2010COM$pct_prog3 <- NULL

round(cor(w2010COM$pct_natl2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_natl2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_natl2))/nrow(w2010COM)*100
## N
w2010COM$pct_natl2 <- NULL

round(cor(w2010COM$pct_natl3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_natl3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_natl3))/nrow(w2010COM)*100
## N
w2010COM$pct_natl3 <- NULL

round(cor(w2010COM$pct_natl4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_natl4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_natl4))/nrow(w2010COM)*100
## N
w2010COM$pct_natl4 <- NULL

round(cor(w2010COM$pct_natl6, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pct_natl6, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pct_natl6))/nrow(w2010COM)*100
## N
w2010COM$pct_natl6 <- NULL

round(cor(w2010COM$idaamt2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$idaamt2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$idaamt2))/nrow(w2010COM)*100
## N
w2010COM$idaamt2 <- NULL

round(cor(w2010COM$blend, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$blend, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$blend))/nrow(w2010COM)*100
## N
w2010COM$blend <- NULL

round(cor(w2010COM$gdppc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$gdppc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$gdppc))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$landarea, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$landarea, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$landarea))/nrow(w2010COM)*100
## N
w2010COM$landarea <- NULL

round(cor(w2010COM$pop, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pop, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pop))/nrow(w2010COM)*100
## N
w2010COM$pop <- NULL

round(cor(w2010COM$disaster, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$disaster, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$disaster))/nrow(w2010COM)*100
## N
w2010COM$disaster <- NULL

round(cor(w2010COM$polity2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$polity2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$polity2))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$durable, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$durable, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$durable))/nrow(w2010COM)*100
## N
w2010COM$durable <- NULL

round(cor(w2010COM$polrights, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$polrights, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$polrights))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$civlibs, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$civlibs, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$civlibs))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$revpolrights, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$revpolrights, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$revpolrights))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$revcivlibs, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$revcivlibs, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$revcivlibs))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$fh, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$fh, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$fh))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$voice, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$voice, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$voice))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$voice, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$voice, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$voice))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$polstab, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$polstab, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$polstab))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$goveffect, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$goveffect, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$goveffect))/nrow(w2010COM)*100
## N
w2010COM$goveffect <- NULL

round(cor(w2010COM$regqual, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$regqual, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$regqual))/nrow(w2010COM)*100
## N
w2010COM$regqual <- NULL

round(cor(w2010COM$rulelaw, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$rulelaw, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$rulelaw))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$corruptcontrol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$corruptcontrol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$corruptcontrol))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$corrupt_index, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$corrupt_index, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$corrupt_index))/nrow(w2010COM)*100
## N
w2010COM$corrupt_index <- NULL

round(cor(w2010COM$civilwar, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$civilwar, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$civilwar))/nrow(w2010COM)*100
## N
w2010COM$civilwar <- NULL

round(cor(w2010COM$usexp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usexp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usexp))/nrow(w2010COM)*100
## N
w2010COM$usexp <- NULL

round(cor(w2010COM$imp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$imp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$imp))/nrow(w2010COM)*100
## N
w2010COM$imp <- NULL

round(cor(w2010COM$exp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$exp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$exp))/nrow(w2010COM)*100
## N
w2010COM$exp <- NULL

round(cor(w2010COM$usimp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usimp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usimp))/nrow(w2010COM)*100
## N
w2010COM$usimp <- NULL

round(cor(w2010COM$ustrade, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$ustrade, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$ustrade))/nrow(w2010COM)*100
## N
w2010COM$ustrade <- NULL

round(cor(w2010COM$logustrade, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logustrade, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logustrade))/nrow(w2010COM)*100
## N
w2010COM$logustrade <- NULL

round(cor(w2010COM$oecdtrade, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$oecdtrade, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$oecdtrade))/nrow(w2010COM)*100
## N
w2010COM$oecdtrade <- NULL

round(cor(w2010COM$logoecdtrade, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logoecdtrade, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logoecdtrade))/nrow(w2010COM)*100
## N
w2010COM$logoecdtrade <- NULL

round(cor(w2010COM$dac, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$dac, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$dac))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$multoda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$multoda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$multoda))/nrow(w2010COM)*100
## N
w2010COM$multoda <- NULL

round(cor(w2010COM$usoda, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usoda, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usoda))/nrow(w2010COM)*100
## N
w2010COM$usoda <- NULL

round(cor(w2010COM$usmil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usmil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usmil))/nrow(w2010COM)*100
## N
w2010COM$usmil <- NULL

round(cor(w2010COM$usally, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usally, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usally))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$uscol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$uscol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$uscol))/nrow(w2010COM)*100
## N
w2010COM$uscol <- NULL

round(cor(w2010COM$ukcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$ukcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$ukcol))/nrow(w2010COM)*100
## N
w2010COM$ukcol <- NULL

round(cor(w2010COM$nethcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$nethcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$nethcol))/nrow(w2010COM)*100
## N
w2010COM$nethcol <- NULL

round(cor(w2010COM$belcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$belcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$belcol))/nrow(w2010COM)*100
## N
w2010COM$belcol <- NULL

round(cor(w2010COM$frcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$frcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$frcol))/nrow(w2010COM)*100
## N
w2010COM$frcol <- NULL

round(cor(w2010COM$spcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$spcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$spcol))/nrow(w2010COM)*100
## N
w2010COM$spcol <- NULL

round(cor(w2010COM$porcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$porcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$porcol))/nrow(w2010COM)*100
## N
w2010COM$porcol <- NULL

round(cor(w2010COM$ruscol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$ruscol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$ruscol))/nrow(w2010COM)*100
## N
w2010COM$ruscol <- NULL

round(cor(w2010COM$daccol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$daccol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$daccol))/nrow(w2010COM)*100
## N
w2010COM$daccol <- NULL

round(cor(w2010COM$usukfrcol, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usukfrcol, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usukfrcol))/nrow(w2010COM)*100
## N
w2010COM$usukfrcol <- NULL

round(cor(w2010COM$s2un, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$s2un, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$s2un))/nrow(w2010COM)*100
## N
w2010COM$s2un <- NULL

round(cor(w2010COM$s3un, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$s3un, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$s3un))/nrow(w2010COM)*100
## N
w2010COM$s3un <- NULL

round(cor(w2010COM$inlineblg7, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblg7, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblg7))/nrow(w2010COM)*100
## N
w2010COM$inlineblg7 <- NULL

round(cor(w2010COM$inlineblhetg7, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblhetg7, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblhetg7))/nrow(w2010COM)*100
## N
w2010COM$inlineblhetg7 <- NULL

round(cor(w2010COM$inlineblhetusa, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblhetusa, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblhetusa))/nrow(w2010COM)*100
## N
w2010COM$inlineblhetusa <- NULL

round(cor(w2010COM$inlineblmag7, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblmag7, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblmag7))/nrow(w2010COM)*100
## N
w2010COM$inlineblmag7 <- NULL

round(cor(w2010COM$inlineblmausa, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblmausa, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblmausa))/nrow(w2010COM)*100
## N
w2010COM$inlineblmausa <- NULL

round(cor(w2010COM$inlineblusa, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$inlineblusa, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$inlineblusa))/nrow(w2010COM)*100
## N
w2010COM$inlineblusa <- NULL

round(cor(w2010COM$unsc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$unsc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$unsc))/nrow(w2010COM)*100
## N
w2010COM$unsc <- NULL

round(cor(w2010COM$unscrotate, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$unscrotate, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$unscrotate))/nrow(w2010COM)*100
## N
w2010COM$unscrotate <- NULL

round(cor(w2010COM$oil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$oil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$oil))/nrow(w2010COM)*100
## N
w2010COM$oil <- NULL

round(cor(w2010COM$logoil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logoil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logoil))/nrow(w2010COM)*100
## N
w2010COM$logoil <- NULL

round(cor(w2010COM$oecdmigrants, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$oecdmigrants, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$oecdmigrants))/nrow(w2010COM)*100
## N
w2010COM$oecdmigrants <- NULL

round(cor(w2010COM$usmigrants, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$usmigrants, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$usmigrants))/nrow(w2010COM)*100
## N
w2010COM$usmigrants <- NULL

round(cor(w2010COM$logoecdmig, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logoecdmig, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logoecdmig))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$logusmig, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logusmig, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logusmig))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$loggdppc, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$loggdppc, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$loggdppc))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$logpop, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logpop, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logpop))/nrow(w2010COM)*100
## N
w2010COM$logpop <- NULL

round(cor(w2010COM$logarea, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logarea, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logarea))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$logdisas, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logdisas, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logdisas))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$logcommitamt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logcommitamt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logcommitamt))/nrow(w2010COM)*100
## N
w2010COM$logcommitamt <- NULL

round(cor(w2010COM$logprog4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logprog4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logprog4))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$nonprog4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$nonprog4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$nonprog4))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$lognatl5, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$lognatl5, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$lognatl5))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$nonnatl5, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$nonnatl5, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$nonnatl5))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$lognatl6, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$lognatl6, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$lognatl6))/nrow(w2010COM)*100
## N
w2010COM$lognatl6 <- NULL

round(cor(w2010COM$logusmil, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$logusmil, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$logusmil))/nrow(w2010COM)*100
## N
w2010COM$logusmil <- NULL

round(cor(w2010COM$sba, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$sba, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$sba))/nrow(w2010COM)*100
## N
w2010COM$sba <- NULL

round(cor(w2010COM$eff, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$eff, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$eff))/nrow(w2010COM)*100
## N
w2010COM$eff <- NULL

round(cor(w2010COM$prgf, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$prgf, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$prgf))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$saf, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$saf, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$saf))/nrow(w2010COM)*100
## N
w2010COM$saf <- NULL

round(cor(w2010COM$debt, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$debt, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$debt))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$gni, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$gni, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$gni))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$debtgni, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$debtgni, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$debtgni))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$invest, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$invest, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$invest))/nrow(w2010COM)*100
## Y

round(cor(w2010COM$pluralty, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$pluralty, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$pluralty))/nrow(w2010COM)*100
## N
w2010COM$pluralty <- NULL

round(cor(w2010COM$author, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$author, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$author))/nrow(w2010COM)*100
## N
w2010COM$author <- NULL

round(cor(w2010COM$ida1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$ida1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$ida1))/nrow(w2010COM)*100
## Y (need it to distinguish between IDA and IBRD)

round(cor(w2010COM$trueblend, analysis, use = "pairwise.complete.obs"), 2)
round(cor(w2010COM$trueblend, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(w2010COM$trueblend))/nrow(w2010COM)*100
## N
w2010COM$trueblend <- NULL

## Imputation
head(w2010COM)
dim(w2010COM)

## What is average percentage of missing data?
NAs <- function(x) {
    as.vector(apply(x, 2, function(x) length(which(is.na(x)))))
    }
NAs(w2010COM)
mean(NAs(w2010COM)/nrow(w2010COM))*100

## Thus: 5 imputations

set.seed(02138)
w2010.out <- amelia(w2010COM, m = 5, cs = "country", ts = "year", polytime = 3, lags = c("gmavg", "pct_prog4", "pct_natl5"), empri = 0.01*nrow(w2010COM))

write.amelia(obj= w2010.out, file.stem = "W2010 WP Imp Data", format = "dta", separate = FALSE)